package com.example.springsecuritydemo.controller;

import com.example.springsecuritydemo.test.Greeting;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
public class TestController {

    @RequestMapping("/vip{rand}/{id}")
    public String test1(@PathVariable("id") Integer id, @PathVariable("rand") Integer rand, HttpServletResponse response) {
//        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        RestTemplate restTemplate=new RestTemplate();
        return "/views/vip" + rand + "/" + id;
    }

    @RequestMapping("/")
    public String index() {
//        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
//        response.getWriter().write("hello");
        /*new Thread(() -> System.out.println(11)).start();
        new ArrayList<String>();
        for (int i = 0; i < 10; i++) {
            System.out.println(22);
        }

        FunctionInterface<String> functionInterface= (i, b,list2) -> {
            System.out.println(44);
            return new ArrayList<>();
        };*/

        return "/views/index";
    }

    @RequestMapping("/form")
//    @ResponseBody
    public String form(HttpServletRequest request, Model model){
        String name = request.getParameter("name");
        System.out.println(name);
        Greeting greeting=new Greeting(1,"你好啊 敖德萨所多");
        model.addAttribute(greeting);
        return "/views/form";
    }

    @RequestMapping("/myLogin")
    public String myLogin(){
        return "/views/myLogin";
    }

}

interface FunctionInterface<String>{
    List<String> fun(int i, String b,List<String> list2);
}
